/*
 * @Author: lixiang
 * @Date: 2021-10-22 17:20:53
 * @Description: 
 */
/*
 * @Author: lixiang
 * @Date: 2020-06-11 10:58:07
 * @Description: 弹框封装
 */
import { Dialog } from "vant";
/**
 * @description: model
 * @param {type}
 * @return:
 */

function model(
  content,
  confirmButtonText,
  showCancelButton = true,
  cancelButtonText = "取消",
  title = "提示",
  messageAlign = "center"
) {
  return new Promise((resolve, reject) => {
    Dialog.confirm({
      title: title,
      message: content,
      showCancelButton: showCancelButton,
      cancelButtonText: cancelButtonText,
      confirmButtonText: confirmButtonText,
      messageAlign: messageAlign,
      confirmButtonColor: "#83c956",
      "overlay-style": { "line-height": "1.8 !important" },
      beforeClose
    })
      .then(res => {
        resolve(res);
        // on confirm
      })
      .catch(err => {
        reject(err);
        // on cancel
      });
  });
}

function beforeClose(action, done) {
  if (action === "confirm") {
    setTimeout(done, 1000);
  } else {
    done();
  }
}

export default {
  model,
  beforeClose
};
